package com.qf.ex;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class MyHandleException implements HandlerExceptionResolver {
    /**
     *
     * @param httpServletRequest 请求对象
     * @param httpServletResponse 响应对象
     * @param o 处理器
     * @param e 异常对象
     * @return 方法返回值 ModelAndView 替换error.jsp
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("msg","张彦卓又出异常了");
        modelAndView.setViewName("/error.jsp");
        return modelAndView;
    }
}
